package cn.tedu.duotai;

public class Pet {
    String name;
    int age;
    public Pet(){}
    public Pet(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public void eat(){
        System.out.println("吃~~");
    }
}
class Cat extends Pet{
    public Cat(String name,int age) {
        super(name,age);
    }

    @Override
    public void eat() {
        System.out.println("猫抓鱼");
        super.eat();
    }
    public void catMethod(){
        System.out.println("cat 特有的方法");
    }
}
class Dog extends Pet{
    @Override
    public void eat() {
        System.out.println("狗刨骨头");
        super.eat();
    }
    public void dogMethod(){
        System.out.println("dog 特有的方法");
    }
}
class Master{
    String name;
    Pet pet;
}
/*
class PetShop{
    String name;//宠物店的名称
//    Cat cat;
//    Cat cat1;
    private Cat[] cats = new Cat[]{new Cat("猫1",1),new Cat("猫2",1),new Cat("猫3",1)};
    Dog[] dogs = new Dog[]{new Dog(),new Dog()};

    public void sell(Pet pet){
        System.out.println("要卖出的宠物信息："+pet.name+","+pet.age);
    }
    //遍历打印cats数组
    public void showCats(){
        //foreach
        for (Cat cat:cats) {
            System.out.println(cat.name+","+cat.age);
        }
    }
    public void showDogs(){
        //foreach
        for (Dog dog:dogs) {
            System.out.println(dog.name+","+dog.age);
        }
    }
}*/
class PetShop{
    String name;//宠物店的名称
    Pet[] pets = new Pet[]{new Dog(),new Cat("猫1",2)};//pets[0] = new Dog();
    //查询所有宠物
    public void showPets(){
        /*for (Pet pet:pets) {
            System.out.println(pet.name+","+pet.age);
        }*/
        for (Pet pet:pets) {
            //pet
            if(pet instanceof Dog){
                //pet变量是不是Dog类型的对象
                System.out.println("狗"+pet.name+","+pet.age);
                Dog dog = (Dog) pet;
                dog.dogMethod();
            }else if(pet instanceof Cat){
                System.out.println("猫"+pet.name+","+pet.age);
                Cat cat = (Cat) pet;
                cat.catMethod();
            }

        }
    }
}

